package com.example.onlineeducation.utils

import com.yc.jetpacklib.extension.YcAnyExt
import com.yc.jetpacklib.extension.ycTryReturnData


object YcAnyExt {

    @JvmStatic
    var mCommonDefaultInt: Int = 0

}

/**
 * 转成Double类型，格式错误返回空
 */
fun String?.ycToInt(): Int? = ycTryReturnData(block = {
    return@ycTryReturnData this?.toInt()
}, error = {
    return@ycTryReturnData null
})

/**
 * 转成非空的Double类型，格式错误返回空
 */
fun String?.ycToIntNoEmpty(defaultData: Int = YcAnyExt.mCommonDefaultInt): Int =
    ycTryReturnData(block = {
        return@ycTryReturnData this?.toInt() ?: defaultData
    }, error = {
        return@ycTryReturnData defaultData
    })

